<template>
  <basic-container>
    <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="基础配置" prop="status">
        <el-radio-group v-model="form.status">
          <el-radio width="100%" label="1">默认不限制</el-radio>
          <el-radio width="100%" label="2">随机链接设置限制，此链接只允许1个ip访问，并且10分钟后失效。（失效后打开是404）</el-radio>
          <el-radio width="100%" label="3">随机链接设置限制，此链接只允许打开一次，点击一次后失效，无时间限制。（二次访问打开是404）</el-radio>
          <el-radio width="100%" label="4">随机链接设置限制，此链接只允许点击一次，10分钟后无论有没有点击都失效</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">保存配置</el-button>
      </el-form-item>
    </el-form>


  </basic-container>

</template>

<style scoped>
/deep/ .el-radio{
  display: block;
  line-height: 40px;
  white-space: normal;
  margin-right: 0;
}
</style>



<script>

import {gameLinksettings,save} from "@/api/game/game";


export default {
  data() {
    return {

      form:{
        id:'',
        status:'1',
      },

      rules: {
        status: [
          { required: true, message: '请选择活动资源', trigger: 'change' }
        ],
      },
    }

  },

  computed: {

  },
  created() {
    this.onload();

  },
  methods: {



    isNotEmpty(arr) {
      return arr != null && arr.length !== 0
    },
    isEmpty(arr) {
      return !this.isNotEmpty(arr)
    },

    /* 确定 */
    submitForm(ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          console.log("hihi",this.form)
          save(this.form).then(res => {
            if (res.data.success) {
              this.$message({
                type: "success",
                message: "新增信息成功!"
              });
              this.onSubmit();
            } else {
              this.$message({
                type: "error",
                message: res.data.msg
              });
            }
          })
        } else {
          return false
        }
      })


    },
    onSubmit() {
      this.onload();
    },
    onload(){

      gameLinksettings().then(res => {
        console.log("resres",res)
        const data = res.data.data;
        console.log("datadata1",data.id)
        console.log("datadata2",data.status)
         if(Object.keys(data).length!=0){
           console.log("qwqw")
           this.$set(this.form, 'id', data.id);
           this.$set(this.form, 'status', data.status + '');
       }
      });
    },

  }
}
</script>

<style>

</style>
